﻿// <copyright file="Response.cs" company="Ucaya">
// </copyright>
// <author>Ucaya</author>

namespace MediaRss
{
    #region

    using System;
    using System.Xml;
    using System.Xml.Serialization;

    #endregion

    [XmlRoot(ElementName = "response", Namespace = "http://search.yahoo.com/mrss/")]
    public class Response : MediaRssBase, IXmlSerializable
    {
        #region Constants and Fields

        internal const string ELEMENT_NAME = "response";

        #endregion

        #region Public Properties

        public Uri ResponseLink { get; set; }

        #endregion

        #region Public Methods

        public void ReadXml(XmlReader reader)
        {
            bool isEmptyElement = reader.IsEmptyElement;
            base.AddAttributeExtensions(reader);
            reader.ReadStartElement();
            if (!isEmptyElement)
            {
                this.ResponseLink = new Uri(reader.ReadContentAsString());
            }
            reader.ReadEndElement();
        }

        public void WriteXml(XmlWriter writer)
        {
            writer.WriteStartElement("media", "response", "http://search.yahoo.com/mrss/");
            foreach (var pair in base.AttributeExtensions)
            {
                writer.WriteAttributeString(pair.Key.Name, pair.Key.Namespace, pair.Value);
            }
            if (this.ResponseLink != null)
            {
                writer.WriteString(this.ResponseLink.ToString());
            }
            writer.WriteEndElement();
            foreach (var element in base.ElementExtensions)
            {
                element.WriteTo(writer);
            }
        }

        #endregion
    }
}